/**
 *                            License
 * THE WORK (AS DEFINED BELOW) IS PROVIDED UNDER THE TERMS OF THIS  
 * CREATIVE COMMONS PUBLIC LICENSE ("CCPL" OR "LICENSE"). 
 * THE WORK IS PROTECTED BY COPYRIGHT AND/OR OTHER APPLICABLE LAW.  
 * ANY USE OF THE WORK OTHER THAN AS AUTHORIZED UNDER THIS LICENSE OR  
 * COPYRIGHT LAW IS PROHIBITED.
 * 
 * BY EXERCISING ANY RIGHTS TO THE WORK PROVIDED HERE, YOU ACCEPT AND  
 * AGREE TO BE BOUND BY THE TERMS OF THIS LICENSE. TO THE EXTENT THIS LICENSE  
 * MAY BE CONSIDERED TO BE A CONTRACT,
 * THE LICENSOR GRANTS YOU THE RIGHTS CONTAINED 
 * HERE IN CONSIDERATION OF YOUR ACCEPTANCE OF SUCH TERMS AND CONDITIONS.
 * 
 */
package com.lineage.server.model.skill.executor;

import com.lineage.server.PacketCreate;
import com.lineage.server.model.L1Character;
import com.lineage.server.model.L1PcInventory;
import com.lineage.server.model.Instance.L1ItemInstance;
import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.model.skill.L1SkillExecutor;
import com.lineage.server.packetserver.S_ServerMessage;
import com.lineage.server.packetserver.ServerBasePacket;

/**
 * Class <code>CreateMagicalWeapon</code> 法师魔法:创造魔法武器 (200/0/10).
 * 将未有魔法性质的武器变成加一的魔法武器，此魔法对具有魔法性质的武器无任何效果。（未开放）
 * 
 * @author jrwz
 * @version 2012-7-27上午10:04:47
 * @see com.lineage.server.model.skill.executor
 * @since JDK1.7
 */
public final class CreateMagicalWeapon extends L1SkillExecutor {

    /**
     * 取得实例.
     * 
     * @return 实例
     */
    public static L1SkillExecutor get() {
        return new CreateMagicalWeapon();
    }

    /** 法师魔法:创造魔法武器 (200/0/10). */
    private CreateMagicalWeapon() {
    }

    @Override
    public void execute(final L1Character user, final L1Character cha,
            final L1Character target, final int targetID, final int skillId,
            final int getBuffIconDuration) {
        if (cha instanceof L1PcInstance) {
            final L1PcInstance pc = (L1PcInstance) cha;
            final L1ItemInstance item = pc.getInventory().getItem(targetID);
            if ((item != null) && (item.getItem().getType2() == 1)) {
                final int itemType = item.getItem().getType2();
                final int safeEnchant = item.getItem().getSafeenchant();
                final int enchantLevel = item.getEnchantLevel();
                String itemName = item.getName();
                if (safeEnchant < 0) { // 安定值小于0无法强化
                    PacketCreate.get().sendSinglePackets(pc, "没有任何事情发生");
                } else if (safeEnchant == 0) { // 安定值0无法强化
                    PacketCreate.get().sendSinglePackets(pc, "没有任何事情发生");
                } else if ((itemType == 1) && (enchantLevel == 0)) {
                    if (!item.isIdentified()) { // 未鉴定
                        final ServerBasePacket msg = new S_ServerMessage(161,
                                itemName, "$245", "$247");
                        pc.sendPackets(msg); // \f1%0%s %2 %1 光芒。
                    } else {
                        itemName = "+0 " + itemName;
                        final ServerBasePacket msg = new S_ServerMessage(161,
                                "+0 " + itemName, "$245", "$247");
                        pc.sendPackets(msg); // \f1%0%s %2 %1 光芒。
                    }
                    item.setEnchantLevel(1);
                    pc.getInventory().updateItem(item,
                            L1PcInventory.COL_ENCHANTLVL);
                } else {
                    PacketCreate.get().sendSinglePackets(pc, "没有任何事情发生");
                }
            } else {
                PacketCreate.get().sendSinglePackets(pc, "没有任何事情发生");
            }
        }
    }

    @Override
    public void stop(final L1Character cha, final int skillId) {
        // TODO Auto-generated method stub
    }
}
